package com.lizhenhua.fmmall.service.serviceImpl;

import com.lizhenhua.fmmall.entity.UserAddr;
import com.lizhenhua.fmmall.mapper.UserAddrMapper;
import com.lizhenhua.fmmall.service.UserAddrService;
import com.lizhenhua.fmmall.vo.ResStatus;
import com.lizhenhua.fmmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class UserAddrServiceImpl implements UserAddrService {

    @Autowired
    UserAddrMapper userAddrMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    public ResultVo getAddressByUserId(Integer userId) {
        Example example = new Example(UserAddr.class);

        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);

        criteria.andEqualTo("status",1);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);

        for (UserAddr u: userAddrs
             ) {

        }
        if (userAddrs.size() > 0) {
            return new ResultVo(ResStatus.OK, "success", userAddrs);

        } else {
            return new ResultVo(ResStatus.OK, "fail", null);

        }
    }
}
